package com.moorror.codegenvel.common.table.bean;

import com.moorror.codegenvel.common.table.AColumnDesc;
import com.moorror.codegenvel.common.table.ColumnShowAttr;
import com.moorror.codegenvel.common.table.ColumnValueEnum;
import org.apache.commons.compress.utils.Lists;

import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;

/**
 * @Author jiyanghuang
 * @Date 2025/8/25 21:53
 */
public class TableSQLColumn extends AbstractTableStringRow<TableSQLColumn>{

    @AColumnDesc(nameShow = "Row", order = 1, cellEditable = false, columnShowAttr = ColumnShowAttr.INDEX)
    private Integer row;

    @AColumnDesc(nameShow = "name", order = 2, vcFun = "updateValue")
    private String name;

    @AColumnDesc(nameShow = "type", order = 10, vcFun = "updateValue")
    private String type;

    @AColumnDesc(nameShow = "comment", order = 20, vcFun = "updateValue")
    private String comment;

    @AColumnDesc(nameShow = "disable", order = 30, vcFun = "updateValue", valueType = ColumnValueEnum.CHECKBOX)
    private boolean disable;

    @AColumnDesc(nameShow = "support", order = 40, vcFun = "updateValue", valueTypeValuesKey = "", valueType = ColumnValueEnum.SELECT)
    private String support;

    private BiConsumer<TableSQLColumn, TableSQLColumn> updateConsumer;

    public static List<TableSQLColumn> ofMock(){
        List<TableSQLColumn> list = Lists.newArrayList();
        TableSQLColumn tableSQLColumn = new TableSQLColumn();
        tableSQLColumn.setName("name1");
        tableSQLColumn.setType("string1");
        tableSQLColumn.setComment("comment1");
        tableSQLColumn.setType("1");
        tableSQLColumn.setDisable(true);
        tableSQLColumn.setSupport("one");
        list.add(tableSQLColumn);

        tableSQLColumn = new TableSQLColumn();
        tableSQLColumn.setName("name2");
        tableSQLColumn.setType("string2");
        tableSQLColumn.setComment("comment2");
        tableSQLColumn.setType("2");
        tableSQLColumn.setDisable(false);
        tableSQLColumn.setSupport("one");
        list.add(tableSQLColumn);

        return list;
    }

    public static List<TableSQLColumn> genTableData(List<Map.Entry<String, String>> strings, BiConsumer<TableSQLColumn, TableSQLColumn> updateConsumer) {
        List<TableSQLColumn> rows = Lists.newArrayList();
//        for (int i = 0; i < strings.size(); i++) {
//            TableSQLColumn redisListRow = new TableSQLColumn();
//            Map.Entry<String, String> entry = strings.get(i);
//            redisListRow.setRow(i);
//            redisListRow.setValue(entry.getValue());
//            redisListRow.setField(entry.getKey());
//            redisListRow.setTypeEnum(typeEnum);
//            redisListRow.setUpdateConsumer(updateConsumer);
//            rows.add(redisListRow);
//        }
        return rows;
    }

    public void updateValue(TableSQLColumn old, TableSQLColumn update) {
        if(null != updateConsumer){
            updateConsumer.accept(old, update);
        }
    }


    @Override
    public TableSQLColumn copyThis() {
        TableSQLColumn redisListRow = new TableSQLColumn();
        redisListRow.setRow(this.getRow());
        redisListRow.setName(this.getName());
        redisListRow.setType(this.getType());
        redisListRow.setComment(this.getComment());
        redisListRow.setComment(this.getComment());
        redisListRow.setDisable(this.getDisable());
        redisListRow.setSupport(this.getSupport());
        return redisListRow;
    }

    @Override
    public TableSQLColumn newRowDefault() {
        this.setName("name2");
        this.setType("string2");
        this.setComment("comment2");
        this.setType("2");
        this.setDisable(false);
        this.setSupport("one");
        return this;
    }

    public Integer getRow() {
        return row;
    }

    public void setRow(Integer row) {
        this.row = row;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public boolean getDisable() {
        return disable;
    }

    public void setDisable(boolean disable) {
        this.disable = disable;
    }

    public String getSupport() {
        return support;
    }

    public void setSupport(String support) {
        this.support = support;
    }

    public BiConsumer<TableSQLColumn, TableSQLColumn> getUpdateConsumer() {
        return updateConsumer;
    }

    public void setUpdateConsumer(BiConsumer<TableSQLColumn, TableSQLColumn> updateConsumer) {
        this.updateConsumer = updateConsumer;
    }
}
